#include "stdafx.h"
#include "Draw.h"



Draw::Draw(CClientDC * dc, const int& _height) :mapWidth(_height)
{
	this->dc = dc;
	this->mapePen = new CPen(PS_SOLID, 5, RGB(91, 188, 142));
	this->headPen = new CPen(PS_SOLID, 5, RGB(0, 0, 0));
	this->bodyPen = new CPen(PS_SOLID, 5, RGB(191, 156, 67));
	this->foodPen = new CPen(PS_SOLID, 5, RGB(253, 111, 1));
}

Draw::~Draw()
{
	this->bodyPen->DeleteObject();
	delete bodyPen;
	this->headPen->DeleteObject();
	delete headPen;
	this->mapePen->DeleteObject();
	delete mapePen;
	this->foodPen->DeleteObject();
	delete foodPen;
}

void Draw::drawSnake()
{
	SnakeBody *head, *move;
	move=head = list->getHead();
	//int x=head->x, y=head->y;
	dc->SelectObject(this->headPen);
	dc->Rectangle(head->x, head->y, head->x + snakeBody, head->y + snakeBody);
	dc->SelectObject(this->bodyPen);
	move = move->next;
	while (move!=nullptr)
	{
		dc->Rectangle(move->x, move->y, move->x + snakeBody, move->y + snakeBody);
		move = move->next;
	}
}

void Draw::drawMap()
{
	this->dc->SelectObject(mapePen);
	dc->MoveTo(0, 0);
	dc->LineTo(0, mapWidth);
	dc->LineTo(mapWidth, mapWidth);
	dc->LineTo(mapWidth, 0);
	dc->LineTo(0, 0);
	//mapePen->DeleteObject();
	//delete mapePen;
}

void Draw::drawFood(const int & x, const int & y) const
{
	this->dc->SelectObject(this->foodPen);
	dc->Rectangle(x, y, x + snakeBody, y + snakeBody);
}

void Draw::setSnakeList(SnakeList* list)
{
	this->list = list;
}
